<!-- src/views/Register.vue -->
<template>
    <el-container>
      <el-header>
        <TopNavbar />
      </el-header>
      <el-main style="padding: 20px;">
        <el-card>
          <h2>注册</h2>
          <el-form :model="form" ref="formRef">
            <el-form-item label="用户名">
              <el-input v-model="form.username" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
              <el-input v-model="form.password" type="password" placeholder="请输入密码"></el-input>
            </el-form-item>
            <el-form-item label="确认密码">
              <el-input v-model="form.confirmPassword" type="password" placeholder="请确认密码"></el-input>
            </el-form-item>
            <el-button type="primary" @click="submitForm">注册</el-button>
          </el-form>
        </el-card>
      </el-main>
    </el-container>
  </template>
  
  <script>
  import { ref } from 'vue';
  import { useRouter } from 'vue-router';
  
  export default {
    setup() {
      const formRef = ref(null);
      const router = useRouter();
      const form = ref({
        username: '',
        password: '',
        confirmPassword: '',
      });
  
      const submitForm = () => {
        if (!form.value.username || !form.value.password || !form.value.confirmPassword) {
          alert('请填写完整的用户名和密码');
          return;
        }
        if (form.value.password !== form.value.confirmPassword) {
          alert('两次输入的密码不一致');
          return;
        }
        // 模拟注册成功
        alert('注册成功');
        router.push('/login');
      };
  
      return {
        form,
        formRef,
        submitForm,
      };
    },
  };
  </script>